package com.xique.park.service.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xique.park.bean.domain.VerifyRecords;
import com.xique.park.mapper.VerifyRecordsMapper;
import com.xique.park.service.service.IVerifyRecordsService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * VerifyRecordsServiceImpl
 *
 * @author xique
 */
@RequiredArgsConstructor
@Service
public class VerifyRecordsServiceImpl extends ServiceImpl<VerifyRecordsMapper, VerifyRecords> implements IVerifyRecordsService {

    private final VerifyRecordsMapper verifyRecordsMapper;

    @Override
    public VerifyRecords getCurrent(Long parkId, Date starDate, Date endDate) {
        return verifyRecordsMapper.getCurrent(parkId, starDate, endDate);
    }

    @Override
    public List<VerifyRecords> selectCountByMonth(Integer year, Integer startMonth, Integer endMonth, Long parkId) {
        VerifyRecords verifyRecords;
        List<VerifyRecords> verifyRecordsList = new ArrayList<>();
        for (int month = startMonth; month <= endMonth; month++) {
            if (month <= 0) {
                int newMonth = month + 12;
                int newYear = year - 1;
                verifyRecords = verifyRecordsMapper.selectCountByMonth(newYear, newMonth, parkId);
                verifyRecords.setTime(newYear + "-" + newMonth);
            } else {
                verifyRecords = verifyRecordsMapper.selectCountByMonth(year, month, parkId);
                verifyRecords.setTime(year + "-" + month);
            }
            verifyRecordsList.add(verifyRecords);
        }
        return verifyRecordsList;
    }

}
